package com.commerceerp.system.controller;


import com.commerceerp.system.entity.Constant;
import com.commerceerp.system.entity.PushGoodInfo;
import com.commerceerp.system.service.PushGoodService;
import com.commerceerp.system.service.WinitService;
import com.commerceerp.system.service.WishService;
import com.commerceerp.system.util.ApiResult;
import com.commerceerp.system.util.DateUtil;
import com.commerceerp.system.util.RdPage;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;

@Api(description = "商品发布接口", value = "商品发布接口")
@Scope("prototype")
@RestController
@EnableAutoConfiguration
public class PushGoodController {

    @Autowired
    private PushGoodService pushGoodService;

    @Autowired
    private WishService wishService;

    @ApiOperation(value = "查询发布商品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "platfrom", value = "平台类型()", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "type", value = "搜索类型(1:时间，2:商品名称，3:SKU)", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "content", value = "内容", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgStatus", value = "发布商品的状态(1:待发布，2:发布中,3:发布成功，4:发布失败)", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "current", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "记录数", required = true, dataType = "Integer")
    })
    @RequestMapping(value = "/getAllPushGoodByStatus", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult getAllPushGoodByStatus(@RequestParam(value = "platfrom", required = false) String platfrom,
                                        @RequestParam(value = "type", required = false) String type,
                                        @RequestParam(value = "content", required = false) String content,
                                        @RequestParam(value = "pgStatus", required = false) String pgStatus,
                                        @RequestParam(value = "current") Integer current,
                                        @RequestParam(value = "pageSize") Integer pageSize) throws IOException {

        ApiResult result = null;
        PageHelper.startPage(Integer.valueOf(current), Integer.valueOf(pageSize));
        String pgCreateTime = null;
        String pgName = null;
        String pgSku = null;
        if("1".equals(type)){
            pgCreateTime = content;
        }else if("2".equals(type)){
            pgName = content;
        }else if("3".equals(type)){
            pgSku = content;
        }

        PushGoodInfo pushGoodInfo = new PushGoodInfo();
        pushGoodInfo.setPgCreateTime(pgCreateTime);
        pushGoodInfo.setPgPlatfrom(platfrom);
        pushGoodInfo.setPgStatus(pgStatus);
        pushGoodInfo.setPgName(pgName);
        pushGoodInfo.setPgSku(pgSku);

        List<Map> list = pushGoodService.getAllPushGoodByStatus(pushGoodInfo);

        //获取分页信息
        PageInfo<Map> pageInfo = new PageInfo<>(list);
        RdPage rdPage = RdPage.getPageInfo(pageInfo, String.valueOf(current), String.valueOf(pageSize));

        result = new ApiResult(Constant.SUCCEED_CODE_VALUE,"查询成功",list,rdPage);

        return result;
    }


    @ApiOperation(value = "编辑发布商品")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pgId", value = "平台类型()", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgName", value = "产品名称（必填）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgDeclaredName", value = "物流申报的产品名称", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgPieces", value = "与此商品相关的件数", required = false, dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "pgTags", value = "用逗号分隔的描述产品的字符串列表。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgSku", value = "系统用来识别此产品的唯一标识符（必填）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgColor", value = "可选产品的颜色。例如：红色，蓝色，绿色)", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgSize", value = "可选产品的大小。例如：大，中，小，5,6,7.5", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgInventory", value = "此产品的物理量最多为500,000（必填）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgPrice", value = "用户购买一个的变化的价格，最多100,000（必填）", required = false, dataType = "Decimal"),
            @ApiImplicitParam(paramType = "query", name = "pgShipping", value = "当用户购买一件时，产品的运送，最多1000件（必填）", required = false, dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "pgMsrp", value = "可选的制造商建议零售价", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgShippingTime", value = "可选运送到达买方所需的时间。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgMainImage", value = "您产品照片的网址。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgParentSku", value = "可选在定义产品的变体时，我们必须知道将变体附加到哪个产品", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgBrand", value = "可选品牌或您的产品的制造商", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgLandingPageUrl", value = "包含产品详细信息的网站上的可选网址", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgUpc", value = "可选的 12位通用产品代码（UPC）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgExtraImages", value = "您的产品额外照片的可选网址。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgMaxQuantity", value = "可选每件订单的最大产品数量", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgLength", value = "可选包装发运给客户的产品长度（以厘米为单位）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgWidth", value = "可选您的产品将被包装运送给客户的宽度（以厘米为单位）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgHeight", value = "可选您的产品将被包装以运送给客户的高度（以厘米为单位）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgWeight", value = "可选您的产品的重量将包装发货给客户（单位为g）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgDeclaredValue", value = "可选您的产品的价格将被宣布为定制。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgHscode", value = "可选的用于定制声明的统一系统代码。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgOriginCountry", value = "产品制造的可选国家。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgHasPowder", value = "可选产品是否含有粉末(true/false)", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgHasLiquid", value = "可选产品是否含有液体。(true/false)", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgHasBattery", value = "可选产品是否含有电池(true/false)", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgHasMetal", value = "可选产品是否含有金属(true/false)", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgCreateTime", value = "创建时间", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgStatus", value = "发布商品状态(1:待发布，2:发布中,3:发布成功，4:发布失败)", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgPlatfromStore", value = "发布的平台和店铺，如(1_1,2_2,3_3)", required = false, dataType = "String"),

    })
    @RequestMapping(value = "/updPushGoodById", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult updPushGoodById(@RequestParam(value = "pgId", required = false) Integer pgId,
                                            @RequestParam(value = "pgName", required = false) String pgName,
                                            @RequestParam(value = "pgDeclaredName", required = false) String pgDeclaredName,
                                            @RequestParam(value = "pgPieces", required = false) Integer pgPieces,
                                            @RequestParam(value = "pgTags", required = false) String pgTags,
                                            @RequestParam(value = "pgSku", required = false) String pgSku,
                                            @RequestParam(value = "pgColor", required = false) String pgColor,
                                            @RequestParam(value = "pgSize", required = false) String pgSize,
                                            @RequestParam(value = "pgInventory", required = false) String pgInventory,
                                            @RequestParam(value = "pgPrice", required = false) BigDecimal pgPrice,
                                            @RequestParam(value = "pgShipping", required = false) Integer pgShipping,
                                            @RequestParam(value = "pgMsrp", required = false) String pgMsrp,
                                            @RequestParam(value = "pgShippingTime", required = false) String pgShippingTime,
                                            @RequestParam(value = "pgMainImage", required = false) String pgMainImage,
                                            @RequestParam(value = "pgParentSku", required = false) String pgParentSku,
                                            @RequestParam(value = "pgBrand", required = false) String pgBrand,
                                            @RequestParam(value = "pgLandingPageUrl", required = false) String pgLandingPageUrl,
                                            @RequestParam(value = "pgUpc", required = false) String pgUpc,
                                            @RequestParam(value = "pgExtraImages", required = false) String pgExtraImages,
                                            @RequestParam(value = "pgMaxQuantity", required = false) String pgMaxQuantity,
                                            @RequestParam(value = "pgLength", required = false) String pgLength,
                                            @RequestParam(value = "pgWidth", required = false) String pgWidth,
                                            @RequestParam(value = "pgHeight", required = false) String pgHeight,
                                            @RequestParam(value = "pgWeight", required = false) String pgWeight,
                                            @RequestParam(value = "pgDeclaredValue", required = false) String pgDeclaredValue,
                                            @RequestParam(value = "pgHscode", required = false) String pgHscode,
                                            @RequestParam(value = "pgOriginCountry", required = false) String pgOriginCountry,
                                            @RequestParam(value = "pgHasPowder", required = false) String pgHasPowder,
                                            @RequestParam(value = "pgHasLiquid", required = false) String pgHasLiquid,
                                            @RequestParam(value = "pgHasBattery", required = false) String pgHasBattery,
                                            @RequestParam(value = "pgHasMetal", required = false) String pgHasMetal,
                                            @RequestParam(value = "pgCreateTime", required = false) String pgCreateTime,
                                            @RequestParam(value = "pgStatus", required = false) String pgStatus,
                                            @RequestParam(value = "pgPlatfromStore", required = false) String pgPlatfromStore) throws IOException {

        ApiResult result = null;

        String[] platfromAndStore = pgPlatfromStore.split(",");
        StringBuffer platfroms = new StringBuffer();
        StringBuffer stores = new StringBuffer();

        Boolean flag = false;
        for(String tmp : platfromAndStore){

            Integer index = tmp.indexOf("_");
            String platfrom = tmp.substring(0,index);
            String store = tmp.substring(index,tmp.length());

            if(true){
                platfroms.append(",");
                platfroms.append(platfrom);
                stores.append(",");
                stores.append(store);
            } else {
                platfroms.append(platfrom);
                stores.append(store);
                flag = true;
            }

        }

        PushGoodInfo pushGoodInfo = new PushGoodInfo();

        pushGoodInfo.setPgId(pgId);
        pushGoodInfo.setPgName(pgName);
        pushGoodInfo.setPgDeclaredName(pgDeclaredName);
        pushGoodInfo.setPgPieces(pgPieces);
        pushGoodInfo.setPgTags(pgTags);
        pushGoodInfo.setPgSku(pgSku);
        pushGoodInfo.setPgColor(pgColor);
        pushGoodInfo.setPgSize(pgSize);
        pushGoodInfo.setPgInventory(pgInventory);
        pushGoodInfo.setPgPrice(pgPrice);
        pushGoodInfo.setPgShipping(pgShipping);
        pushGoodInfo.setPgMsrp(pgMsrp);
        pushGoodInfo.setPgShippingTime(pgShippingTime);
        pushGoodInfo.setPgMainImage(pgMainImage);
        pushGoodInfo.setPgParentSku(pgParentSku);
        pushGoodInfo.setPgBrand(pgBrand);
        pushGoodInfo.setPgLandingPageUrl(pgLandingPageUrl);
        pushGoodInfo.setPgUpc(pgUpc);
        pushGoodInfo.setPgExtraImages(pgExtraImages);
        pushGoodInfo.setPgMaxQuantity(pgMaxQuantity);
        pushGoodInfo.setPgLength(pgLength);
        pushGoodInfo.setPgWidth(pgWidth);
        pushGoodInfo.setPgHeight(pgHeight);
        pushGoodInfo.setPgWeight(pgWeight);
        pushGoodInfo.setPgDeclaredValue(pgDeclaredValue);
        pushGoodInfo.setPgHscode(pgHscode);
        pushGoodInfo.setPgOriginCountry(pgOriginCountry);
        pushGoodInfo.setPgHasPowder(pgHasPowder);
        pushGoodInfo.setPgHasLiquid(pgHasLiquid);
        pushGoodInfo.setPgHasBattery(pgHasBattery);
        pushGoodInfo.setPgHasMetal(pgHasMetal);
        pushGoodInfo.setPgCreateTime(pgCreateTime);
        pushGoodInfo.setPgStatus(pgStatus);
        pushGoodInfo.setPgPlatfrom(platfroms.toString());
        pushGoodInfo.setPgStore(stores.toString());

        Integer success = pushGoodService.updPushGoodById(pushGoodInfo);

        if(success == 1){
            result = new ApiResult(Constant.SUCCEED_CODE_VALUE,"成功",null,null);
        }else{
            result = new ApiResult(Constant.FAIL_CODE_VALUE,"失败",null,null);
        }

        return result;
    }



    @ApiOperation(value = "根据id查找发布商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pgId", value = "发布商品id", required = false, dataType = "String"),
    })
    @RequestMapping(value = "/getPushGoodBuPgId", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult getPushGoodBuPgId(@RequestParam(value = "pgId", required = false) String pgId) throws IOException {

        ApiResult result = null;

        PushGoodInfo pgInfo = pushGoodService.getPushGoodBuPgId(pgId);

        result = new ApiResult(Constant.SUCCEED_CODE_VALUE,"查询成功",pgInfo,null);

        return result;
    }


    @ApiOperation(value = "删除发布商品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pgId", value = "发布商品id", required = false, dataType = "String"),
    })
    @RequestMapping(value = "/delPushGoodById", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult delPushGoodById(@RequestParam(value = "pgId", required = false) String pgId) throws IOException {

        ApiResult result = null;

        Integer success = pushGoodService.delPushGoodById(pgId);

        if(success == 1){
            result = new ApiResult(Constant.SUCCEED_CODE_VALUE,"成功",null,null);
        }else{
            result = new ApiResult(Constant.FAIL_CODE_VALUE,"失败",null,null);
        }

        return result;
    }


    @ApiOperation(value = "创建发布商品")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "pgName", value = "产品名称（必填）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgDescription", value = "产品描述（必填）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgDeclaredName", value = "物流申报的产品名称", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgDeclaredLocalName", value = "产品名称用当地语言写成，用于物流申报", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgPieces", value = "与此商品相关的件数", required = false, dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "pgTags", value = "用逗号分隔的描述产品的字符串列表。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgSku", value = "系统用来识别此产品的唯一标识符（必填）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgColor", value = "可选产品的颜色。例如：红色，蓝色，绿色)", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgSize", value = "可选产品的大小。例如：大，中，小，5,6,7.5", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgInventory", value = "此产品的物理量最多为500,000（必填）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgPrice", value = "用户购买一个的变化的价格，最多100,000（必填）", required = false, dataType = "Decimal"),
            @ApiImplicitParam(paramType = "query", name = "pgShipping", value = "当用户购买一件时，产品的运送，最多1000件（必填）", required = false, dataType = "Integer"),
            @ApiImplicitParam(paramType = "query", name = "pgMsrp", value = "可选的制造商建议零售价", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgShippingTime", value = "可选运送到达买方所需的时间。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgMainImage", value = "您产品照片的网址。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgParentSku", value = "可选在定义产品的变体时，我们必须知道将变体附加到哪个产品", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgBrand", value = "可选品牌或您的产品的制造商", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgLandingPageUrl", value = "包含产品详细信息的网站上的可选网址", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgUpc", value = "可选的 12位通用产品代码（UPC）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgExtraImages", value = "您的产品额外照片的可选网址。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgMaxQuantity", value = "可选每件订单的最大产品数量", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgLength", value = "可选包装发运给客户的产品长度（以厘米为单位）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgWidth", value = "可选您的产品将被包装运送给客户的宽度（以厘米为单位）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgHeight", value = "可选您的产品将被包装以运送给客户的高度（以厘米为单位）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgWeight", value = "可选您的产品的重量将包装发货给客户（单位为g）", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgDeclaredValue", value = "可选您的产品的价格将被宣布为定制。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgHscode", value = "可选的用于定制声明的统一系统代码。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgOriginCountry", value = "产品制造的可选国家。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgHasPowder", value = "可选产品是否含有粉末(true/false)", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgHasLiquid", value = "可选产品是否含有液体(true/false)。", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgHasBattery", value = "可选产品是否含有电池(true/false)", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgHasMetal", value = "可选产品是否含有金属(true/false)", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgPlatfromStoreId", value = "发布的平台和店铺id，如(1_1,2_2,3_3)", required = false, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "pgStoreName", value = "发布店铺名称，如(1,2,3)", required = false, dataType = "String"),


    })
    @RequestMapping(value = "/saveNewPushGood", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult saveNewPushGood(
                                     @RequestParam(value = "pgName", required = false) String pgName,
                                     @RequestParam(value = "pgDescription", required = false) String pgDescription,
                                     @RequestParam(value = "pgDeclaredName", required = false) String pgDeclaredName,
                                     @RequestParam(value = "pgDeclaredLocalName", required = false) String pgDeclaredLocalName,
                                     @RequestParam(value = "pgPieces", required = false) Integer pgPieces,
                                     @RequestParam(value = "pgTags", required = false) String pgTags,
                                     @RequestParam(value = "pgSku", required = false) String pgSku,
                                     @RequestParam(value = "pgColor", required = false) String pgColor,
                                     @RequestParam(value = "pgSize", required = false) String pgSize,
                                     @RequestParam(value = "pgInventory", required = false) String pgInventory,
                                     @RequestParam(value = "pgPrice", required = false) BigDecimal pgPrice,
                                     @RequestParam(value = "pgShipping", required = false) Integer pgShipping,
                                     @RequestParam(value = "pgMsrp", required = false) String pgMsrp,
                                     @RequestParam(value = "pgShippingTime", required = false) String pgShippingTime,
                                     @RequestParam(value = "pgMainImage", required = false) String pgMainImage,
                                     @RequestParam(value = "pgParentSku", required = false) String pgParentSku,
                                     @RequestParam(value = "pgBrand", required = false) String pgBrand,
                                     @RequestParam(value = "pgLandingPageUrl", required = false) String pgLandingPageUrl,
                                     @RequestParam(value = "pgUpc", required = false) String pgUpc,
                                     @RequestParam(value = "pgExtraImages", required = false) String pgExtraImages,
                                     @RequestParam(value = "pgMaxQuantity", required = false) String pgMaxQuantity,
                                     @RequestParam(value = "pgLength", required = false) String pgLength,
                                     @RequestParam(value = "pgWidth", required = false) String pgWidth,
                                     @RequestParam(value = "pgHeight", required = false) String pgHeight,
                                     @RequestParam(value = "pgWeight", required = false) String pgWeight,
                                     @RequestParam(value = "pgDeclaredValue", required = false) String pgDeclaredValue,
                                     @RequestParam(value = "pgHscode", required = false) String pgHscode,
                                     @RequestParam(value = "pgOriginCountry", required = false) String pgOriginCountry,
                                     @RequestParam(value = "pgHasPowder", required = false) String pgHasPowder,
                                     @RequestParam(value = "pgHasLiquid", required = false) String pgHasLiquid,
                                     @RequestParam(value = "pgHasBattery", required = false) String pgHasBattery,
                                     @RequestParam(value = "pgHasMetal", required = false) String pgHasMetal,
                                     @RequestParam(value = "pgPlatfromStoreIds", required = false) String pgPlatfromStoreIds,
                                     @RequestParam(value = "pgStoreNames", required = false) String pgStoreNames) throws IOException {

        ApiResult result = null;

        String[] platfromAndStore = pgPlatfromStoreIds.split(",");
        StringBuffer platfroms = new StringBuffer();
        StringBuffer storeIds = new StringBuffer();

        Boolean flag = false;
        for(String tmp : platfromAndStore){

            Integer index = tmp.indexOf("_");
            String platfrom = tmp.substring(0,index);
            String storeId = tmp.substring(index,tmp.length());

            if(platfroms.toString().contains("wish")){

                wishService.productAdd(storeId, pgName, pgDescription, pgDeclaredName, pgDeclaredLocalName,
                        pgPieces.toString(), pgTags, pgSku, pgColor, pgSize, pgInventory, pgPrice.toString(),
                        pgShipping.toString(), pgMsrp, pgShippingTime, pgMainImage, pgParentSku, pgBrand,
                        pgLandingPageUrl, pgUpc, pgExtraImages, pgMaxQuantity, pgLength, pgWidth,
                        pgHeight, pgWeight, pgDeclaredValue, pgHscode, pgOriginCountry, pgHasPowder,
                        pgHasLiquid, pgHasBattery, pgHasMetal);
            }

            if(true){
                platfroms.append(",");
                platfroms.append(platfrom);
                storeIds.append(",");
                storeIds.append(storeId);
            } else {
                platfroms.append(platfrom);
                storeIds.append(storeId);
                flag = true;
            }
        }

        PushGoodInfo pushGoodInfo = new PushGoodInfo();
        pushGoodInfo.setPgName(pgName);
        pushGoodInfo.setPgDescription(pgDescription);
        pushGoodInfo.setPgDeclaredName(pgDeclaredName);
        pushGoodInfo.setPgDeclaredLocalName(pgDeclaredLocalName);
        pushGoodInfo.setPgPieces(pgPieces);
        pushGoodInfo.setPgTags(pgTags);
        pushGoodInfo.setPgSku(pgSku);
        pushGoodInfo.setPgColor(pgColor);
        pushGoodInfo.setPgSize(pgSize);
        pushGoodInfo.setPgInventory(pgInventory);
        pushGoodInfo.setPgPrice(pgPrice);
        pushGoodInfo.setPgShipping(pgShipping);
        pushGoodInfo.setPgMsrp(pgMsrp);
        pushGoodInfo.setPgShippingTime(pgShippingTime);
        pushGoodInfo.setPgMainImage(pgMainImage);
        pushGoodInfo.setPgParentSku(pgParentSku);
        pushGoodInfo.setPgBrand(pgBrand);
        pushGoodInfo.setPgLandingPageUrl(pgLandingPageUrl);
        pushGoodInfo.setPgUpc(pgUpc);
        pushGoodInfo.setPgExtraImages(pgExtraImages);
        pushGoodInfo.setPgMaxQuantity(pgMaxQuantity);
        pushGoodInfo.setPgLength(pgLength);
        pushGoodInfo.setPgWidth(pgWidth);
        pushGoodInfo.setPgHeight(pgHeight);
        pushGoodInfo.setPgWeight(pgWeight);
        pushGoodInfo.setPgDeclaredValue(pgDeclaredValue);
        pushGoodInfo.setPgHscode(pgHscode);
        pushGoodInfo.setPgOriginCountry(pgOriginCountry);
        pushGoodInfo.setPgHasPowder(pgHasPowder);
        pushGoodInfo.setPgHasLiquid(pgHasLiquid);
        pushGoodInfo.setPgHasBattery(pgHasBattery);
        pushGoodInfo.setPgHasMetal(pgHasMetal);
        pushGoodInfo.setPgCreateTime(DateUtil.getYMDHMSDate());
        pushGoodInfo.setPgStatus("1");
        pushGoodInfo.setPgPlatfrom(platfroms.toString());
        pushGoodInfo.setPgStore(pgStoreNames);
        pushGoodInfo.setPgStoreId(storeIds.toString());

        Integer success = pushGoodService.saveNewPushGood(pushGoodInfo);

        if(success == 1){
            result = new ApiResult(Constant.SUCCEED_CODE_VALUE,"成功",null,null);
        }else{
            result = new ApiResult(Constant.FAIL_CODE_VALUE,"失败",null,null);
        }

        return result;
    }

    @ApiOperation(value = "商品发布页面各状态数量")
    @ApiImplicitParams({

    })
    @RequestMapping(value = "/getCountByPgStatus", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult getCountByPgStatus( ) throws IOException {

        ApiResult result = null;

        List<Map> list = pushGoodService.getCountByPgStatus();

        result = new ApiResult(Constant.SUCCEED_CODE_VALUE,"成功",list,null);

        return result;
    }

    @ApiOperation(value = "文件上传")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "file", value = "文件", required = false, dataType = "String"),
    })
    //上传图片文件
    @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
    @ResponseBody
    public ApiResult uploadFile(@RequestParam("file") MultipartFile file) {
        if (!file.isEmpty()) {
            String resumeurl = "";
            try {
                //重新生成文件名，避免乱码问题
                String filename = file.getOriginalFilename();
                String fName = null;
                if (filename.indexOf(".") >= 0) {
                    fName = filename.substring(filename.lastIndexOf("."), filename.length());
                }
                String path = String.valueOf(new Random().nextInt(100)).concat((fName));//拼接新文件名
                resumeurl = String.valueOf(new Date().getTime()).concat(path);
                File f = new File("static/file/");
                if (!f.exists()) {
                    f.mkdirs();
                }
                BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("static/file/" + new File(resumeurl)));
                out.write(file.getBytes());
                out.flush();
                out.close();
                return new ApiResult("http://47.97.199.140/upload/file/"  + resumeurl);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                return new ApiResult(0, "上传失败："+ e.getMessage(), "上传失败," + e.getMessage(), null);
            } catch (IOException e) {
                e.printStackTrace();
                return new ApiResult(0, "上传失败："+ e.getMessage(), "上传失败," + e.getMessage(), null);
            } catch (Exception e) {
                e.printStackTrace();
                return new ApiResult(0, "上传失败："+ e.getMessage(), "上传失败," + e.getMessage(), null);
            }
        } else {
            return new ApiResult(0, "上传失败，因为文件是空的", null,null);
        }
    }

}
